//
//  AIFCheckPayPwdManager.m
//  PywSdk
//
//  Created by smallwave on 16/9/10.
//  Copyright © 2016年 zero. All rights reserved.
//

#import "AIFCheckPayPwdManager.h"
#import "PywRSAUtil.h"

@implementation AIFCheckPayPwdManager

NSString *const CheckPayPwd_TID = @"tid";
NSString *const CheckPayPwd_GAMEID = @"gameid";
NSString *const CheckPayPwd_SIGN = @"sign";
NSString *const CheckPayPwd_PASSPORT_TOKEN = @"passport_token";
NSString *const CheckPayPwd_TOKEN = @"token";
NSString *const CheckPayPwd_PAY_PWD = @"pay_pwd";
NSString *const CheckPayPwd_USERNAME = @"username";

- (instancetype)init
{
    self = [super init];
    if (self) {
        self.child = self;
        self.paramSource = self;
        self.validate = self;
    }
    return self;
}

#pragma mark - ETAPIManager
- (NSString *)methodName{
    return URL_CHECKPAYPWD;
}

- (ETAPIManagerRequestType)requestType{
    return ETAPIManagerRequestTypePost;
}


- (NSString *)seriviceType{
    return [PywAppInfo sharedAppInfo].seriviceType;
}

#pragma mark - ETAPIManagerParamSourceDelegate

- (NSDictionary *)paramsForApi:(ETApiBaseManager *)manager{
    
    //流水号
    NSString *gameid = [PywAppInfo sharedAppInfo].gameId;
    NSString *username = [PywPlatformMain sharedPlatformMain].userName;
    
    NSString *pay_pwd = [PywRSAUtil encryptString:self.pay_pwd];
    NSString *tid = [[PywAppInfo sharedAppInfo] tid];
    NSString *apiSecret2 = [AppUtil getApiSecret2:tid apiSecret:[PywAppInfo sharedAppInfo].apisecret];
    
    NSString *sign = [NSString stringWithFormat:@"%@%@%@",username,self.pay_pwd,apiSecret2];
    sign = [PywCipherUtils md5:sign];
    
    
    MutableDictionary *param = [[MutableDictionary alloc] init];
    if ([PywPlatformMain sharedPlatformMain].accountType == UserType_Passport) { // 平台账号
        NSString *passport_token = [PywPlatformMain sharedPlatformMain].passport_Token;
        [param setObject:passport_token forKey:CheckPayPwd_PASSPORT_TOKEN];
    } else {
        NSString *token = [PywPlatformMain sharedPlatformMain].token;
        [param setObject:token forKey:CheckPayPwd_TOKEN];
    }
    [param setObject:tid forKey:CheckPayPwd_TID];
    [param setObject:gameid forKey:CheckPayPwd_GAMEID];
    [param setObject:sign forKey:CheckPayPwd_SIGN];
    [param setObject:pay_pwd forKey:CheckPayPwd_PAY_PWD];
    [param setObject:username forKey:CheckPayPwd_USERNAME];
    return param;
}

#pragma mark - ETAPIManagerValidator
- (BOOL)manager:(ETApiBaseManager *)manager isCorrectWithParamsData:(NSDictionary *)data{
    return YES;
}

- (BOOL)manager:(ETApiBaseManager *)manager isCorrectWithCallBackData:(NSDictionary *)data{
    return YES;
}


@end
